/*
 *所有关于ak_wgjy_sgd_peizhi类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*ak_wgjy_sgd_peizhiService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using DGZImp.Core.BaseProvider;
using DGZImp.Core.Extensions.AutofacManager;
using ATkg.BizAppProject.DomainModels;
using System.Linq;
using DGZImp.Core.Utilities;
using System.Linq.Expressions;
using DGZImp.Core.Extensions;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using ATkg.BizAppProject.IRepositories;
using Newtonsoft.Json.Linq;
using DGZImp.Core.DbSqlSugar;
using DocumentFormat.OpenXml.VariantTypes;

namespace ATkg.BizAppProject.Services
{
    public partial class ak_wgjy_sgd_peizhiService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Iak_wgjy_sgd_peizhiRepository _repository;//访问数据库

        [ActivatorUtilitiesConstructor]
        public ak_wgjy_sgd_peizhiService(
            Iak_wgjy_sgd_peizhiRepository dbRepository,
            IHttpContextAccessor httpContextAccessor
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        public async Task<object> search_gx_detail_all()
        {
            var find_data3 = Db.Queryable<ak_wgjy_sgd_peizhi>()
                    .Where(m => m.IsValid == 1)
                    .ToList();
            return new
            {
                rows = find_data3,
                total = 1
            };
        }
        [SugarTable("ak_wgjy_sgd")] // 映射表名
        public class ak_wgjy_sgd
        {
            [SugarColumn(IsPrimaryKey = true)] // 主键标识（若存在）
            public string workOrderNo { get; set; }
            public string productCode { get; set; }
            public string batchNo { get; set; }
            public string productSpec { get; set; }
            public string grade { get; set; }
            public string coating { get; set; }
            public string unitWeight { get; set; }
            public string batchQuantity { get; set; }
            public string qualifiedQuantity { get; set; }
            public string batchWeight { get; set; }
            public string packagingWeight { get; set; }
            public string startTime { get; set; }
            public string endTime { get; set; }
            public string inspectors { get; set; }
            public string status { get; set; }
            public string quantity { get; set; }
            public string totalTime { get; set; } 

        }
        public async Task<object> insert_gx_info(string option_type, JArray mes_data_final)
        {
            Console.WriteLine(option_type);
            Console.WriteLine(mes_data_final);
            if(option_type == "创建")
            {
                Console.WriteLine("创建进来了");
                for(int i = 0; i < mes_data_final.Count; i++)
                {
                    var per = mes_data_final[i];
                    var final_data_info_ = new List<ak_wgjy_sgd>();
                    string result1 = string.Join(", ", per["inspectors"]);
                    final_data_info_.Add(new ak_wgjy_sgd
                    {
                        workOrderNo = (string)per["workOrderNo"],
                        productCode = (string)per["productCode"],
                        batchNo = (string)per["batchNo"],
                        productSpec = (string)per["productSpec"],
                        grade = (string)per["grade"],
                        coating = (string)per["coating"],
                        unitWeight = (string)per["unitWeight"],
                        batchQuantity = (string)per["batchQuantity"],
                        qualifiedQuantity = (string)per["qualifiedQuantity"],
                        batchWeight = (string)per["batchWeight"],
                        packagingWeight = (string)per["packagingWeight"],
                        startTime = (string)per["startTime"],
                        endTime = (string)per["endTime"],
                        inspectors = result1,
                        status = (string)per["status"],
                        quantity = (string)per["quantity"],
                        totalTime = (string)per["totalTime"]
                    });
                    await Db.DoInsertAsync<ak_wgjy_sgd>(final_data_info_);
                }
            }
            var find_data3 = Db.Queryable<ak_wgjy_sgd_peizhi>()
                    .ToList();
            return new
            {
                rows = find_data3,
                total = 1
            };
        }
        public async Task<object> search_info_db_all()
        {
            var find_data3 = Db.Queryable<ak_wgjy_sgd>()
                    .ToList();
            return new
            {
                rows = find_data3,
                total = find_data3.Count
            };
        }
    }
}
